﻿#include <stdio.h>
#include "threadpool.h"

//测试函数
void taskFunc(void* arg)
{
	int num = *(int*)arg;
	printf("thread %ld is working, number = %d\n",
		pthread_self(), num);
	//srand((unsigned)time(NULL));
	usleep(rand() % 10000 + 10000);
	int* i = (int*)malloc(sizeof(int));
	*i = rand();
	free(i);
}

void demo()
{
}

int main()
{
	//demo();
	int n = 10000;
	// 创建线程池，线程数3-10 ，任务容量100
	ThreadPool* pool = threadPoolCreate(4, 8, n);

	for (int i = 0; i < n; ++i)
	{
		int* num = (int*)malloc(sizeof(int));
		*num = i;
		threadPoolAdd(pool, taskFunc, num);//向线程池加任务
	}

	sleep(20);

	threadPoolDestroy(pool);
	return 0;
}